package org.one.stone.soup.grfxML.plugin.geometry;


import org.one.stone.soup.grfxML.DataPoint;
import org.one.stone.soup.grfxML.GrfxMLEngine;
import org.one.stone.soup.grfxML.plugin.SimplePlugin;
import org.one.stone.soup.grfxML.plugin.grfxMLCaster;
import org.one.stone.soup.mjdb.data.field.DataLinker;
import org.one.stone.soup.mjdb.data.field.Field;
import org.one.stone.soup.mjdb.data.field.LockException;

public class Spiral extends SimplePlugin {


	public static final int ARG_RADIUS = 0;

	public static final int ARG_RADIUSINCREASE = 1;

	public static final int ARG_DEGREES = 2;

	public static final int ARG_TARGET = 3;



	org.one.stone.soup.grfxML.DataSize radius = new org.one.stone.soup.grfxML.DataSize(10);

	org.one.stone.soup.grfxML.DataSize radiusIncrease = new org.one.stone.soup.grfxML.DataSize(0);

	org.one.stone.soup.grfxML.DataSize degrees = new org.one.stone.soup.grfxML.DataSize(100);

	org.one.stone.soup.grfxML.DataPoints target = new org.one.stone.soup.grfxML.DataPoints();


/**
 * Spiral constructor comment.
 */
public Spiral (GrfxMLEngine engine){
	super(engine);
}
/**
 *
 */
public void calculate()
{
 try{
	int r = radius.getValue();
	int dr = radiusIncrease.getValue();
	int cdr;
	int cr;
	int stepsV = degrees.getValue();

	target.setEmpty();

	for(int loop=0;loop<stepsV;loop+=5)
	{
		DataPoint p = new DataPoint();
		cdr = (loop*dr/360);
		cr = (loop*(r+cdr)/stepsV);
		p.setValueX( org.one.stone.soup.math.IntMath.sin(loop,cr),this );
		p.setValueY( org.one.stone.soup.math.IntMath.cos(loop,cr),this );
		target.add( p,this );
	}
 }catch(LockException le){}
}
/**
 * initialize method comment.
 */
public void initialize()
{
	calculate();
}
/**
 * process method comment.
 */
public void process()
{
	calculate();
}
/**
 * register method comment.
 */
public void register(DataLinker store)
{

	radius = grfxMLCaster.cast(radius,getArg(radius,ARG_RADIUS,store));

	radiusIncrease = grfxMLCaster.cast(radiusIncrease,getArg(radiusIncrease,ARG_RADIUSINCREASE,store));

	degrees = grfxMLCaster.cast(degrees,getArg(degrees,ARG_DEGREES,store));

	target = grfxMLCaster.cast(target,getArg(target,ARG_TARGET,store));

}
/**
 * replace method comment.
 */
public void replace(Field oldObj, Field newObj)
{

	radius = grfxMLCaster.replace(radius,oldObj,newObj);

	radiusIncrease = grfxMLCaster.replace(radiusIncrease,oldObj,newObj);

	degrees = grfxMLCaster.replace(degrees,oldObj,newObj);

	target = grfxMLCaster.replace(target,oldObj,newObj);

}
/**
 * stop method comment.
 */
public void stop() {}
}
